From 6512129517306e38df0b936aeb870eb294042105 Mon Sep 17 00:00:00 2001 From: tsteven4 <13596209+tsteven4@users.noreply.github.com> Date: Fri, 28 Apr 2023 15:09:21 -0600 Subject: [PATCH] move skytraq away from C style legacy time. (#1092) Co-authored-by: Robert Lipe --- skytraq.cc | 16 ++++++++-------- skytraq.h | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/skytraq.cc b/skytraq.cc index d5b791e7f..a228e6e65 100644 --- a/skytraq.cc +++ b/skytraq.cc @@ -29,7 +29,6 @@ #include // for sscanf, snprintf, vprintf, SEEK_SET #include // for free #include // for memset -#include // for time, time_t #include // for QByteArray #include // for QChar @@ -502,8 +501,8 @@ unsigned int SkytraqBase::me_read32(const unsigned char* p) return ((unsigned)be_read16(p+2) << 16) | ((unsigned)be_read16(p)); } -time_t -SkytraqBase::gpstime_to_timet(int week, int sec) const +QDateTime +SkytraqBase::gpstime_to_qdatetime(int week, int sec) const { /* Notes: * * week rollover period can be specified using option @@ -519,11 +518,12 @@ SkytraqBase::gpstime_to_timet(int week, int sec) const * * overflow of sec into next week is allowed * (i.e. sec >= 7*24*3600 = 604800 is allowed) */ - time_t gps_timet = 315964800; /* Jan 06 1980 0:00 UTC */ + qint64 gps_timet = 315964800; /* Jan 06 1980 0:00 UTC */ int week_rollover = xstrtoi(opt_gps_week_rollover, nullptr, 10); if (week_rollover < 0) { - int current_week = (time(nullptr)-gps_timet)/(7*SECONDS_PER_DAY); + int current_week = (QDateTime::currentSecsSinceEpoch() - gps_timet)/ + (7*SECONDS_PER_DAY); week_rollover = current_week/1024 - (week > current_week%1024 ? 1 : 0); } gps_timet += (week+week_rollover*1024)*7*SECONDS_PER_DAY + sec; @@ -531,7 +531,7 @@ SkytraqBase::gpstime_to_timet(int week, int sec) const int override = xstrtoi(opt_gps_utc_offset, nullptr, 10); if (override) { gps_timet -= override; - return gps_timet; + return QDateTime::fromSecsSinceEpoch(gps_timet); } /* leap second compensation: */ @@ -554,7 +554,7 @@ SkytraqBase::gpstime_to_timet(int week, int sec) const // Future: Consult http://maia.usno.navy.mil/ser7/tai-utc.dat // use http://www.stevegs.com/utils/jd_calc/ for Julian to UNIX sec - return gps_timet; /* returns UTC time */ + return QDateTime::fromSecsSinceEpoch(gps_timet); /* returns UTC time */ } void @@ -612,7 +612,7 @@ SkytraqBase::make_trackpoint(struct read_state* st, double lat, double lon, doub wpt->latitude = lat; wpt->longitude = lon; wpt->altitude = alt; - wpt->SetCreationTime(gpstime_to_timet(st->gps_week, st->gps_sec)); + wpt->SetCreationTime(gpstime_to_qdatetime(st->gps_week, st->gps_sec)); return wpt; } diff --git a/skytraq.h b/skytraq.h index d7d6fe76b..89c7c4bd4 100644 --- a/skytraq.h +++ b/skytraq.h @@ -25,15 +25,15 @@ #ifndef SKYTRAQ_H_INCLUDED_ #define SKYTRAQ_H_INCLUDED_ -#include // for QString -#include // for QVector +#include // for QDateTime +#include // for QString +#include // for QVector -#include // for uint8_t, int32_t, uint32_t, uint16_t, int16_t -#include // for time_t +#include // for uint8_t, int32_t, uint32_t, uint16_t, int16_t -#include "defs.h" // for arglist_t, ARGTYPE_INT, ff_cap, ARG_NOMINMAX, ARGTYPE_STRING, ff_cap_read, ARGTYPE_BOOL, ff_cap_none, ff_type, ARGTYPE_OUTFILE, ff_type_serial, Waypoint, ff_type_file, route_head -#include "format.h" // for Format -#include "gbfile.h" // for gbfile +#include "defs.h" +#include "format.h" // for Format +#include "gbfile.h" // for gbfile class SkytraqBase @@ -128,7 +128,7 @@ protected: int skytraq_configure_logging() const; int skytraq_get_log_buffer_status(uint32_t* log_wr_ptr, uint16_t* sectors_free, uint16_t* sectors_total) const; static unsigned int me_read32(const unsigned char* p); - time_t gpstime_to_timet(int week, int sec) const; + QDateTime gpstime_to_qdatetime(int week, int sec) const; static void ECEF_to_LLA(double x, double y, long int z, double* lat, double* lon, double* alt); static void state_init(read_state* pst); Waypoint* make_trackpoint(read_state* st, double lat, double lon, double alt) const; -- 2.30.2